import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter_chat/common/router/routers.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

import 'global.dart';

final easyLoading = EasyLoading.init();
final botToastInit = BotToastInit();

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Global.init();
  runApp(const App());
}

class App extends StatefulWidget {
  const App({super.key});

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  void initState() {
    super.initState();
    Global.onInitAsync();
  }

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      builder: (context, widget) {
        widget = easyLoading(context, widget);
        widget = botToastInit(context, widget);
        return widget;
      },
      navigatorObservers: [BotToastNavigatorObserver()],
      theme: ThemeData(
        colorScheme: ColorScheme.fromSwatch(),
        useMaterial3: false,
        scaffoldBackgroundColor: const Color(0xffF5F5F5),
      ),
      defaultTransition: Transition.cupertino,
      getPages: AppPages.pages,
      initialRoute: AppPages.initialRoute,
    );
  }
}
